//
//  ElectrolTicketOrderTableViewCell.m
//  PropertyManager
//
//  Created by TNG on 2018/8/4.
//  Copyright © 2018年 Tng. All rights reserved.
//

#import "ElectrolTicketOrderTableViewCell.h"

@implementation ElectrolTicketOrderTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

-(instancetype) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self creatUI];
        self.backgroundColor = SFM242;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}

-(void)creatUI{
    [self.contentView addSubview:self.bgView];
    [self.bgView addSubview:self.img];
    [self.bgView addSubview:self.ordLabel];
    [self.bgView addSubview:self.orderDetailLabel];
    [self.bgView addSubview:self.contractLabel];
    [self.bgView addSubview:self.contractDetailLabel];
    [self.bgView addSubview:self.dashedView];
    [self drawDashLine:self.dashedView lineLength:4 lineSpacing:1 lineColor:SFM242];
}

-(UIView *)bgView
{
    if (_bgView == nil) {
        _bgView = [[UIView alloc] initWithFrame:CGRectMake(15, 35, WIDTH - 30, 170)];
        _bgView.backgroundColor = SFMWhiteColor;
    }
    return _bgView;
}

-(UIImageView *)img
{
    if (_img == nil) {
        _img = [[UIImageView alloc] initWithFrame:CGRectMake(WIDTH/2 - 87, 23, 144, 43)];
        _img.contentMode = UIViewContentModeScaleAspectFill;
        _img.clipsToBounds = YES;
    }
    return _img;
}

-(UILabel *)ordLabel
{
    if (_ordLabel == nil) {
        _ordLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 100, 100, 17)];
        _ordLabel.font = font(14);
        _ordLabel.textColor = SFM153;
        _ordLabel.textAlignment = NSTextAlignmentLeft;
        _ordLabel.text = @"订单号";
    }
    return _ordLabel;
}

-(UILabel *)orderDetailLabel
{
    if (_orderDetailLabel == nil) {
        _orderDetailLabel = [[UILabel alloc] initWithFrame:CGRectMake(130, 100, WIDTH - 180, 17)];
        _orderDetailLabel.font = font(14);
        _orderDetailLabel.textColor = SFM51;
        _orderDetailLabel.textAlignment = NSTextAlignmentRight;
    }
    return _orderDetailLabel;
}

-(UILabel *)contractLabel
{
    if (_contractLabel == nil) {
        _contractLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 130, 100, 17)];
        _contractLabel.font = font(14);
        _contractLabel.textColor = SFM153;
        _contractLabel.textAlignment = NSTextAlignmentLeft;
        _contractLabel.text = @"合同名称";
    }
    return _contractLabel;
}

-(UILabel *)contractDetailLabel
{
    if (_contractDetailLabel == nil) {
        _contractDetailLabel = [[UILabel alloc] initWithFrame:CGRectMake(130, 130, WIDTH - 180, 17)];
        _contractDetailLabel.font = font(14);
        _contractDetailLabel.textColor = SFM51;
        _contractDetailLabel.textAlignment = NSTextAlignmentRight;
    }
    return _contractDetailLabel;
}

-(UIView *)dashedView
{
    if (_dashedView == nil) {
        _dashedView = [[UIView alloc] initWithFrame:CGRectMake(20, 175, WIDTH - 70, 1)];
    }
    return _dashedView;
}

/**
 ** lineView:       需要绘制成虚线的view
 ** lineLength:     虚线的宽度
 ** lineSpacing:    虚线的间距
 ** lineColor:      虚线的颜色
 **/
- (void)drawDashLine:(UIView *)lineView lineLength:(int)lineLength lineSpacing:(int)lineSpacing lineColor:(UIColor *)lineColor
{
    CAShapeLayer *shapeLayer = [CAShapeLayer layer];
    [shapeLayer setBounds:lineView.bounds];
    [shapeLayer setPosition:CGPointMake(CGRectGetWidth(lineView.frame) / 2, CGRectGetHeight(lineView.frame))];
    [shapeLayer setFillColor:[UIColor clearColor].CGColor];
    
    //  设置虚线颜色为
    [shapeLayer setStrokeColor:lineColor.CGColor];
    
    //  设置虚线宽度
    [shapeLayer setLineWidth:CGRectGetHeight(lineView.frame)];
    [shapeLayer setLineJoin:kCALineJoinRound];
    
    //  设置线宽，线间距
    [shapeLayer setLineDashPattern:[NSArray arrayWithObjects:[NSNumber numberWithInt:lineLength], [NSNumber numberWithInt:lineSpacing], nil]];
    
    //  设置路径
    CGMutablePathRef path = CGPathCreateMutable();
    CGPathMoveToPoint(path, NULL, 0, 0);
    CGPathAddLineToPoint(path, NULL, CGRectGetWidth(lineView.frame), 0);
    
    [shapeLayer setPath:path];
    CGPathRelease(path);
    
    //  把绘制好的虚线添加上来
    [lineView.layer addSublayer:shapeLayer];
}

-(void)send
{
    self.img.image = [UIImage imageNamed:@"companyImg"];
    self.orderDetailLabel.text = @"1032904789634122398";
    self.contractDetailLabel.text = @"广百物业八月份缴费通知单";
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
